<? require($_SERVER['DOCUMENT_ROOT'] . '/gs-sos/application/views/inc_header.php'); ?>


<? require($_SERVER['DOCUMENT_ROOT'] . '/gs-sos/application/views/inc_cat_banner.php'); ?>
<script language="javascript" src="<? echo base_url(); ?>js/inc_validate_input.js"></script>
<script>
   function deleteProduct(prodId, prdName) {
       if (confirm('คุณต้องการลบสินค้าชิ้นนี้ ใช่หรือไม่ \n\r ' + prdName)) {
           $.post( "<? echo base_url().'Cart' ?>", { action: "<? echo CART_AC_DELCART ?>", PRD_ID:prodId } );
       
           window.location='<? echo base_url() ?>Cart';
       }
   }
    
    function updateCart(){
        var map = {};

        $("input[name*='id']").each(function() {
            map[$(this).attr("name").substring(2)] = $(this).val();
        });

        $.post( "<? echo base_url().'Cart' ?>", { action: "<? echo CART_AC_UPDATECART ?>", MAP:map } );
        
        window.location='<? echo base_url() ?>Cart';
    }
</script>



<div id="main" class="page">
  <header class="page-header">
    <div class="container">
      <h1 class="title">ตะกร้าสินค้า</h1>
    </div>	
  </header>
  <div class="container">
    <div class="row">
      <article class="content span12">

         <? if ($query->num_rows() > 0) { ?>
        
    <form name="cart" method="post" action="cart.php" data-ajax="false">
        <input type="hidden" name="form_action" value="">
        <input type="hidden" name="PRD_ID" value="">

        <div class="table-box">
          <table id="shopping-cart-table" class="shopping-cart-table table table-bordered table-striped">
            <thead>
              <tr>
                <th></th>
                <th class="td-name">สินค้า</th>
                <th class="td-price">ราคา</th>
                <th class="td-qty">จำนวน</th>
                <th class="td-total">รวม</th>
                <th class="td-remove"></th>
              </tr>
            </thead>

            <? $grand_total = 0; ?>

            <tbody>

              <? foreach ($query->result() as $row) { ?>

              <tr>
                <td class="td-images">
                  <a href="<? echo base_url().'Product/prddetail/'.$row->PRD_ID ?>" class="product-image">
                    <img src="<? echo $row->PRD_IMG_1 ?>" alt="" title="" width="70" height="70">
                  </a>
                </td>
                <td class="td-name">
                  <h2 class="product-name">
                      <a href="<? echo base_url().'Product/prddetail/'.$row->PRD_ID ?>"><? echo $row->PRD_NAME ?></a>
                  </h2>
                </td>
 
               <td class="td-price">
                  <div class="price">&#3647;<?= number_format($row->UNIT_PRICE) ?></div>
                </td>
                <td class="td-qty">
                  <input name="id<? echo $row->PRD_ID ?>" class="input-block-level" type="text" value="<? echo $row->QTY ?>" maxlength="2" onblur="validate_numeric(this);">
                </td>
                <td class="td-total">
                  <div class="price">&#3647;<?= number_format($row->UNIT_PRICE * $row->QTY) ?></div>
                </td>
                <td class="td-remove">
                    <a href="#" onClick="deleteProduct(<? echo $row->PRD_ID ?>, '<? echo $row->PRD_NAME ?>');" class="product-remove">
                  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
                    width="16px" height="16px" viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
                    <g>
                    <path fill="#7f7f7f" d="M6,13c0.553,0,1-0.447,1-1V7c0-0.553-0.447-1-1-1S5,6.447,5,7v5C5,12.553,5.447,13,6,13z"/>
                    <path fill="#7f7f7f" d="M10,13c0.553,0,1-0.447,1-1V7c0-0.553-0.447-1-1-1S9,6.447,9,7v5C9,12.553,9.447,13,10,13z"/>
                    <path fill="#7f7f7f" d="M14,3h-1V1c0-0.552-0.447-1-1-1H4C3.448,0,3,0.448,3,1v2H2C1.447,3,1,3.447,1,4s0.447,1,1,1
                      c0,0.273,0,8.727,0,9c0,1.104,0.896,2,2,2h8c1.104,0,2-0.896,2-2c0-0.273,0-8.727,0-9c0.553,0,1-0.447,1-1S14.553,3,14,3z M5,2h6v1
                      H5V2z M12,14H4V5h8V14z"/>
                    </g>
                  </svg>
                  </a><!-- .product-remove -->
                </td>
      	      </tr>

              <? $grand_total += ($row->UNIT_PRICE * $row->QTY); ?>

              <? } ?>

      	    </tbody>
          </table><!-- .shopping-cart-table -->
        </div>
        <table class="shopping-cart-table shopping-cart-table-button table table-bordered table-striped">
          <tr>
            <td class="action">
                <a href="<? echo base_url() ?>"><i class="fa fa-angle-left"></i> เลือกซื้อสินค้าต่อ</a>
              <a href="javascript:;" onClick="updateCart();" class="update"><i class="fa fa-rotate-right"></i> อัพเดตตะกร้าสินค้า</a>
            </td>
          </tr>
        </table>

        </form>

        <div id="car-bottom" class="row">
          <div class="span8">
            &nbsp;
          </div>
          <div class="span4">
            <div class="car-bottom-box bg total">
              <table>
                <tr>
                  <td>รวม</td>
                  <td><span class="price">&#3647;<?= number_format($grand_total); ?></span></td>
                </tr>
                <!--
                <tr class="tr-total">
                  <td>สุทธิ</td>
                  <td><span class="price">&#3647;$1, 500.00</span></td>
                </tr>
                //-->
              </table>
              <div>
                <a href="javascript:;" class="btn btn-large checkout">ดำเนินการ Checkout</a>
              </div>
              <!--<a href="" class="multiple">Checkout with Multiple Addresses</a>-->
            </div>
          </div>
        </div>

        <? } else { ?>

        <div class="row" align="center">
          <h4>ไม่มีรายการสินค้าในตะกร้า</h4>
        </div>
        <? } ?>

      </article><!-- .content -->
    </div>
  </div>
</div><!-- #main -->



<? require($_SERVER['DOCUMENT_ROOT'] . '/gs-sos/application/views/inc_footer.php'); ?>